var httpConf = require("../../../conf/httpModule.js")
var conf = require("../../../conf/niuniuConf.js").niuConf
var utils = require("../../../util/util.js")
var async = require("async")
module.exports = function(app) {
	return new DBRemote(app);
};

var DBRemote = function(app) {
	this.app = app
	DBRemote.app = app
    DBRemote.dbService = this.app.get("dbService")
    if(DBRemote.dbService && DBRemote.dbService.db){
    	DBRemote.db = DBRemote.dbService.db
    }
}



//设置创建茶楼配置
DBRemote.prototype.setTeaConfig = function(data,cb) {
	var cfg = {
		"open" : 100,
		"table1" : 100,
		"table2" : 100,
		"table3" : 100,
		"table4" : 100,
		"table5" : 100,
		"table6" : 100,
		"table7" : 100,
		"table8" : 100,
		"defaultCount" : 4
	}
	for(var i in cfg){
		if(data[i] && typeof(data[i]) === "number" && data[i] >= 0){
			if(i == "defaultCount"){
				if(data[i] > 8){
					cb(false)
					return
				}
			}
			cfg[i] = data[i]
		}
	}
	DBRemote.dbService.db.hmset("config:tea",cfg,function(err) {
		if(err){
			console.log(err)
			cb(false)
		}else{
			cb(true)
		}
	})
	cb(true)
}